#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#
# Copyright © 2019 crane <crane@gosun>
#
# Distributed under terms of the MIT license.

"""
HDU2082_找单词【多重背包】

假设有x1个字母A， x2个字母B,..... x26个字母Z，同时假设字母A的价值为1，字母B的价值为2,..... 字母Z的价值为26。那么，对于给定的字母，可以找到多少价值<=50的单词呢？单词的价值就是组成一个单词的所有字母的价值之和，比如，单词ACM的价值是1+3+14=18，单词HDU的价值是8+4+21=33。(组成的单词与排列顺序无关，比如ACM与CMA认为是同一个单词）.

n
Input
输入首先是一个整数N，代表测试实例的个数。
然后包括N行数据，每行包括26个<=20的整数x1,x2,.....x26.

Output
对于每个测试实例，请输出能找到的总价值<=50的单词数,每个实例的输出占一行。

Sample Input
2
1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
9 2 6 2 10 2 2 5 6 1 0 2 7 0 2 2 7 5 10 6 10 2 10 6 1 9
 
Sample Output
7
379297

"""

class WordsCnt:
    def __init__(self, letter_cnt):
        self.results = [0] * 51
        self.results[0] = 1
        self.tmp_results = [0] * 51

        self.letter_cnt = letter_cnt
        assert len(self.letter_cnt) == 26

    def do_cnt(self):
        for idx in range(26):
            price = idx + 1
            num = self.letter_cnt[idx]

            for n in range(1, num+1):
            # for n in range(0, num+1):
                # print('idx (letter, cnt)  [%s, %s]' % (idx, n))
                value = price * n

                if value  > 50:
                    # 已然是不可能
                    break

                for idx_dyn in range(51):
                    value_dyn = idx_dyn
                    sum_value = value_dyn + value
                    if sum_value <= 50:
                        self.tmp_results[sum_value] += 1 * self.results[idx_dyn]
                        # print("sum %s, letter %s, letter_v %s, result_value %s, cnt %s" % (sum_value, idx, value, idx_dyn, 1 * self.results[idx_dyn]))
                        # if sum_value == 50:
                        #     print(value, value_dyn)
                    else:
                        break

            # self.results, self.tmp_results =  self.tmp_results, self.results
            for i in range(51):
                self.results[i] += self.tmp_results[i]
            self.tmp_results = [0] * 51

            # if num > 0:
            #     print(self.results)
            #     print('\n')


def test():
    letter_cnt = [9, 2, 6, 2, 10, 2, 2, 5, 6, 1, 0, 2, 7, 0, 2, 2, 7, 5, 10, 6, 10, 2, 10, 6, 1, 9]
    w = WordsCnt(letter_cnt)
    w.do_cnt()
    assert sum(w.results)-1 == 379297

    letter_cnt = [1, 1, 1] + 23 * [0]
    w = WordsCnt(letter_cnt)
    w.do_cnt()
    assert sum(w.results)-1 == 7

def main():
    print("start main")
    test()

if __name__ == "__main__":
    main()
